local res = "";
local oldWrite = io.write
local oldPrint = print

io.write = function(v1)
    res = res .. v1
end

_G.print = function(v1)
    res = res .. v1
end

local target = ngx.arg[1]

local pack_files = {
    charecter = "sprpaktool",
    npc = "sprpaktool",
    monster = "sprpaktool",
    map = "maptool",
    effect = "eftpaktool",
    deft = "sprpaktool",
    picdir = "picdirtool",
    trap = "eftpaktool"
}

local pak = pack_files[target]
if pak == nil then
    return "invalid operator"
end
local op = require(pak)
if type(op) == "function" then
    op( target)
end

local shellCommand = {
    npc = "chmod -R 777 /export/arts/pak/npc_pak",
    charecter = "chmod -R 777 /export/arts/pak/charecter_pak",
    monster = "chmod -R 777 /export/arts/pak/monster_pak",
    map = "chmod -R 777 /export/arts/pak/map_splited",
    effect = "chmod -R 777 /export/arts/pak/effect_pak",
    deft = "chmod -R 777 /export/arts/pak/deft_pak",
    picdir = "chmod -R 777 /export/arts/pak/picdir",
    trap = "chmod -R 777 /export/arts/pak/trap_pak",
}

local cmd = shellCommand[target]
if cmd ~= nil then
    os.execute( cmd)
end

io.write = oldWrite
_G.print = oldPrint

return res

